var ctx=window.daijia.ctx;
var lng=window.daijia.lng;
var lat=window.daijia.lat;
var map = null; //地图对象
var offset=0;
var limit=20;
var pagingLimit=20;//显示分页时的条数
var currentTotalElements=0;//当前显示总条数
var pageLoading=true;//是否能滚动加载
var hasShowPages=false;//是否已显示分页
var firstLoadPages=true;//分页初始化时 不自动加载
//筛选条件,
var search_orderNumber=null;
var search_clientPhone=null;
var search_driverPhone=null;
var search_companyName=null;
var search_startTime="";
var search_endTime="";
var search_startFinishTime="";
var search_endFinishTime="";
var search_orderType=[];
var search_status=[];
var search_treatment="";
var driving=null;
var distance=null;
var timeStr=null;
var start = new Array();
var end = new Array(); 

//推荐附近员工
function trclick(obj){
	$(obj).find("input").attr('checked','checked');
	$("#employId").val($(obj).find("input").val());
}
function radioclick(obj){
	$(obj).attr("checked",'checked');
	$("#employId").val($(obj).val());
}

$(document).ready(function(){
	$(document).on("click",".zhuijia",function(){
    	var id = $(this).attr("orderId");
    	window.open(ctx+"/freight/addmore/"+id,"_blank","height=850,width=1220,scrollbars=yes,resizable=no,alwaysRaised=no,toolbar=yes");
    });
	
	window.setInterval("window.location.reload(true)",1000*60); 
	initdata(false);
	//高级搜索
	$(".query-jiant").click(function(){
		var src=$("#jiant").attr("src");
		if(src.indexOf("jiant2")>=0){
			$("#jiant").attr("src",ctx+"/assets/img/jiant.png");
			$(".choose").show(300);
		}else{
			$("#jiant").attr("src",ctx+"/assets/img/jiant2.png");
			$(".choose").hide(300);
		}
	});
	
	//销单
	$(document).on("click",".cancle",function(){
		$("#dialog_cancel_id").val($(this).attr('orderId'));
    	$("#ok_modal_cancel").attr("disabled",false);
    	$('#dialog_cancel').modal();
	});
	$("#close_modal_cancel").click(function(){
		$('#dialog_cancel').modal("hide");
	});
	$("#ok_modal_cancel").click(function(){
			if($("input[name=cancel_reason]:checked").length==0){
				$.scojs_message("请选择销单原因", $.scojs_message.TYPE_ERROR);
				return false;
			}
			if($("input[name=cancel_reason]:checked").val()=="other" && $("#dialog_cancel_content").val().length==0){
				$.scojs_message("请输入销单原因", $.scojs_message.TYPE_ERROR);
				return false;
			}
			var content="";
			if($("input[name=cancel_reason]:checked").val()=="other"){
				content=$("#dialog_cancel_content").val();
			}else{
				content=$("input[name=cancel_reason]:checked").val();
			}
			$(this).attr("disabled",true);
			$.post($(this).attr("action"),{'id':$("#dialog_cancel_id").val(),'cause':content},function(data){
	            if(data.success){
	            	$.scojs_message(data.message, $.scojs_message.TYPE_OK);
	            	 setTimeout(function(){
	 					window.location.reload(true);
	 				}, 1000);
	            }else{
	            	$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
			},'json');
		});
	//备注		
	$(document).on("click",".modifyCash",function(){
			var  orderId=$(this).attr('orderId');
			var orderNo=$(this).attr('orderNo');
			var orderMemo=$(this).attr('orderMemo');
			$('#orderId').val(orderId);
			$('#orderNo').html(orderNo);
			$('#oldmemo').val(orderMemo);
	    	$('#dialog_modifyCash').modal();
	    });
    $("#save").click(function(){
     	$('#dialog_modifyCash').modal("hide");
		$.post(ctx+'/freight/remark',{'id':$('#orderId').val(),'memo':$('#memo').val()},function(data){
           if(data.success){
                $.scojs_message(data.message, $.scojs_message.TYPE_OK);
                setTimeout(function(){
					window.location.reload(true);
				}, 1000);
	       }else{
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                setTimeout(function(){
					window.location.reload(true);
				}, 1000);
	       }
	    },'json');
    });
    $("#close_modal_memo").click(function(){
    	$('#dialog_modifyCash').modal("hide");
    });
	//收回
 	$(document).on("click",".callback",function(){
		$('#orderId3').val($(this).attr('orderId'));
		$('#orderNo3').html($(this).attr('orderNo'));
		$('#dialog_callback').modal();
 	});
	$("#callback").click(function(){
		var cause=$("#cause3").val().trim();
		if(cause==null || cause==""){
  				$.scojs_message("收回原因不能为空", $.scojs_message.TYPE_ERROR);
				setTimeout(function(){
						window.location.reload(true);
				}, 1000);
				return;
		}
   		var params={id:$("#orderId3").val(),cause:$("#cause3").val()}
		$.post(ctx+'/freight/callback',params,function(object){
			if(object.success){
				$('#dialog_callback').modal("hide");
  				$.scojs_message("收回成功", $.scojs_message.TYPE_OK);
  				setTimeout(function(){
						window.location.reload(true);
				}, 1000);
			}else{
				
  				$.scojs_message(object.message, $.scojs_message.TYPE_ERROR);
			}
		});
	});
    $("#close_modal_callback").click(function(){
		$('#dialog_callback').modal("hide");
	});
    //派单
    var startLng;
    var startLat;
    var clientName;
    var clientPhone;
    var fromPlace;
    var paidanTruckType;
    $(document).on("click",".freight_paidan",function(){
    	startLng=$(this).attr("startLng");
    	startLat=$(this).attr("startLat");
    	clientName=$(this).attr("clientName");
    	clientPhone=$(this).attr("clientPhone");
    	fromPlace=$(this).attr("fromPlace");
    	paidanTruckType=$(this).attr("paidanTruckType");
		$("#paidanOrderId").val($(this).attr("orderId"));
		$("#paidanClientName").html("");
		$("#paidanClientPhone").html("");
		$("#paidanFromPlace").html("");
		$("#paidanTruckType").html("");
		$("#dialog_paidan").modal();
	});
    
    $('#dialog_paidan').on('shown.bs.modal', function () {
    	$("#paidanOrderLng").val(startLng);
		$("#paidanOrderLat").val(startLat);
		
		showClientMaker(startLng,startLat);
		getDrivers(startLng,startLat);
		$("#paidanClientName").html(clientName);
		$("#paidanClientPhone").html(clientPhone);
		$("#paidanFromPlace").html(fromPlace);
		$("#paidanTruckTypeName").html(paidanTruckType);
	});
    $('#distance').change(function(){
		showClientMaker($("#paidanOrderLng").val(),$("#paidanOrderLat").val());
		getDrivers($("#paidanOrderLng").val(),$("#paidanOrderLat").val());
	});
    $(document).on("click",".f_paigeita",function(){
		var driverId=$(this).attr("data-id");
		if(window.confirm('确认要派单给该服务人员吗？')){
			$.post(ctx+'/freight/paidan',{'driverId':driverId,'orderId':$("#paidanOrderId").val()},function(data){
				if(data.success){
					$.scojs_message("派单成功", $.scojs_message.TYPE_OK);
					$("#dialog_paidan").modal("hide");
					initdata(false);
				}else{
					$.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
				}
			});
		}
	});
   
	//查询
   
	$("#searchButton").click(function(){
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if($("#startTime").val()!=""){
			if(!DATE_FORMAT.test($("#startTime").val())){
			   $.scojs_message("您输入的开始日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
			   return false;
			}
		}
		
		if($("#endTime").val()!=""){
			if(!DATE_FORMAT.test($("#endTime").val())){
				$.scojs_message("您输入的结束日期格式有误，正确格式如：2016-06-13 12:45", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
		
		if($("#startTime").val()!="" && $("#endTime").val()!=""){
			if($("#startTime").val()>$("#endTime").val()){
				 $.scojs_message("启始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
				 return false;
			}
		}
		
		search_orderNumber=$("#orderNumber").val();
		search_clientPhone=$("#clientPhone").val();
		search_driverPhone=$("#driverPhone").val();
		search_companyName=$("#companyName").val();
		search_startTime=$("#startTime").val();
		search_endTime=$("#endTime").val();
		search_startFinishTime=$("#startFinishTime").val();
		search_endFinishTime=$("#endFinishTime").val();
		search_treatment=(((typeof($("input[name=treatment]:checked").val()) == undefined )|| $("input[name=treatment]:checked").val()==""||typeof($("input[name=treatment]:checked").val())=="undefined")?"":$("input[name=treatment]:checked").val());
		 var orderTypeArr=[];
		$("input[name=orderType]:checked").each(function(index,element){
			orderTypeArr.push($(element).val());
		});
		if(null!=orderTypeArr && orderTypeArr.length>0){
			search_orderType=orderTypeArr.join(",");
		}else{
			search_orderType=[];
		}
		
		var statusArr=[];
		$("input[name=status]:checked").each(function(index,element){
			statusArr.push($(element).val());
		});
		if(null!=statusArr && statusArr.length>0){
			search_status=statusArr.join(",");
		}else{
			search_status=[];
		}
		offset=0;
		initdata(false);
	});
	
	$(document).on("keydown","body",function(){
		if(window.event.keyCode == 13){
			$("#searchButton").click();
		}
	});

	//滚动
//	$(window).scroll(function () {
//        //$(window).scrollTop()这个方法是当前滚动条滚动的距离
//        //$(window).height()获取当前窗体的高度
//        //$(document).height()获取当前文档的高度
//        var bot = 0; //bot是底部距离的高度
//        if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
//           //当底部基本距离+滚动的高度〉=文档的高度-窗体的高度时；
//        	if(pageLoading){
//        		pageLoading=false;
//        		offset+=limit;
//        		initdata(true);
//        	}
//        }
//    });
	$("#export_button").click(function(){
			
		search_orderNumber=$("#orderNumber").val();
		search_clientPhone=$("#clientPhone").val();
		search_driverPhone=$("#driverPhone").val();
		search_companyName=$("#companyName").val();
		search_startTime=$("#startTime").val();
		search_endTime=$("#endTime").val();
		search_startFinishTime=$("#startFinishTime").val();
		search_endFinishTime=$("#endFinishTime").val();
		search_treatment=(((typeof($("input[name=treatment]:checked").val()) == undefined )|| $("input[name=treatment]:checked").val()==""||typeof($("input[name=treatment]:checked").val())=="undefined")?"":$("input[name=treatment]:checked").val());
			window.location=ctx+"/freight/exportOrder?"+"orderNumber="+$("#orderNumber").val()+
			                "&clientPhone="+$("#clientPhone").val()+"&driverPhone="+$("#driverPhone").val()+
			                "&companyName="+$("#companyName").val()+"&orderType="+search_orderType+"&status="+search_status+
			                "&startTime="+$("#startTime").val()+"&endTime="+$("#endTime").val()+"&treatment="+search_treatment+"&startFinishTime="+search_startFinishTime+"&endFinishTime="+search_endFinishTime;
		});
	
	
});

function initdata(isappend){
	$.ajax({
        url : ctx+'/freight/orderlistData',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"orderNumber":search_orderNumber,
        	"clientPhone":search_clientPhone,
        	"driverPhone":search_driverPhone,
        	"companyName":search_companyName,
        	"startTime":search_startTime,
        	"endTime":search_endTime,
        	"orderType":search_orderType,
        	"status":search_status,
        	"treatment":search_treatment,
        	"startFinishTime":search_startFinishTime,
        	"endFinishTime":search_endFinishTime,
        	"pager.offset":offset,
        	"limit":limit,
        },
        success : function(result){
        	var newcontent = '';
        	var totalElements=result.totalElements;
        	$("#NoData").text("");
        	
        	if(totalElements>0){
        		$(result.content).each(function(index,data){
        			var mainButton="";
        			var selectButton="";
        			var stauts="";
        		    if(data.status==0){
        		    	if(hasPermission_freightPaidan){
        		    		mainButton=
            					"<a href='#' orderId='"+data.id+"'truckTypeName='"+data.truckTypeName+"'fromPlace='"+data.startAddress+"' startAddress='"+data.startAddress+"' startLng='"+data.startLng+"' startLat='"+data.startLat+"'  paidanTruckType='"+data.truckTypeName+"'  clientName='"+data.passengerName+"' clientPhone='"+data.passengerPhone
            				+"' class='btn btn-primary btn-xs freight_paidan'>派单</a>";
        		    		
        		    		selectButton+="<li><a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn-link'>查看</a></li>";
        		    	}
        		    	else{
        		    		mainButton="<a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn btn-primary btn-xs'>查看</a>";
        		    	}
        				
        				status="<span class='btn btn-xindan btn-xs'>未派单</span>";
        				
        				if(hasPermission_powercancel){
        					selectButton+="<li><a href='#' orderId='"+data.id+"' orderNo='"+data.orderNo+"' class='btn-link cancle'>销单</a></li>";
        				}
        				if(hasPermission_freightCreate){
        					selectButton+="<li><a href='#' orderId='"+data.id+"' orderNo="+data.orderNo+" class='btn-link zhuijia'>追加</a></li>";
        				}
            		}else if(data.status==1){
            			mainButton="<a href='#'  orderId='"+data.id+"' orderNo='"+data.orderNo+"' class='btn btn-primary btn-xs callback'>收回</a>";
            			selectButton+="<li><a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn-link'>查看</a></li>";
            			status="<span class='btn btn-warning btn-xs'>已派单</span>";
            			if(hasPermission_powercancel){
            				selectButton+="<li><a href='#' orderId='"+data.id+"' orderNo="+data.orderNo+" class='btn-link cancle'>销单</a></li>";
            			}
            			if(hasPermission_freightCreate){
            				selectButton+="<li><a href='#' orderId='"+data.id+"' orderNo="+data.orderNo+" class='btn-link zhuijia'>追加</a></li>";
            			}
            		}else if(data.status==2 || data.status==3 || data.status==4){
            			mainButton="<a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn btn-primary btn-xs'>查看</a>";
            			if(hasPermission_freightCreate){
            				selectButton+="<li><a href='#'  orderId="+data.id+" orderNo="+data.orderNo+"   class='btn-link zhuijia'>追加</a></li>";
            			}
            			selectButton+="<li><a href='#'  orderId="+data.id+" orderNo="+data.orderNo+" class='btn-link cancle'>销单</a></li>";
            			selectButton+="<li><a href='#'  orderId="+data.id+" orderNo="+data.orderNo+" class='btn-link callback'>收回</a></li>";
            			status="<span class='btn btn-danger btn-xs'>已接单</span>";
            		}else if(data.status==5){
            			if(hasPermission_freightCreate){
            				mainButton="<a href='#' orderId='"+data.id+"' orderNo="+data.orderNo+" class='btn btn-primary btn-xs zhuijia'>追加</a>";
            				selectButton+="<li><a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn-link'>查看</a></li>";
            			}
            			else{
            				mainButton="<a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn btn-primary btn-xs'>查看</a>";
            			}
            			
            			status="<span class='btn btn-success btn-xs'>已完成</span>";
            		}else if(data.status==6){
            			if(hasPermission_freightCreate){
            				mainButton="<a href='#' orderId='"+data.id+"' orderNo="+data.orderNo+" class='btn btn-primary btn-xs zhuijia'>追加</a>";
            				selectButton+="<li><a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn-link'>查看</a></li>";
            			}
            			else{
            				mainButton="<a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn btn-primary btn-xs'>查看</a>";
            			}
            			
            			status="<span class='btn btn-default btn-xs'>已销单</span>";
            		}
            		selectButton+="<li><a href='#' orderId='"+data.id+"' orderNo='"+data.orderNo+"' orderMemo='"+data.orderMemo+"' class='btn-link modifyCash'>备注</a></li>";
            		var allButton="<div class='btn-group'>"+
            							mainButton+
									  "<button type='button' class='btn "+"btn-primary"+" btn-xs dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>"+
									    "<span class='caret'></span>"+
									    "<span class='sr-only'>Toggle Dropdown</span>"+
									  "</button>"+
									  "<ul class='dropdown-menu' role='menu'>"+
									  	selectButton+
									  "</ul>"+
									"</div>";
            		//所属公司
            		var companyNameTd="";
            		if(mainCompany){
            			companyNameTd="<td>"+data.companyName+"</td>";
            		}
            		var couponSpan="";
            		if(data.couponId!=null){
            			couponSpan="<span class='label status-td' style='color:#D4DDF1;background-color:#0063C3;'>券</span>";
            		}
            		var memotr=data.memoStr;
            		if(null!=memotr && memotr.length>10){
            			memotr=memotr.substring(0,10)+"...";
            		}
            		//加收费用
            		var guoluMoney;
            		var yuanchengMoney;
            		var otherMoney;
            		if(data.guoluMoney>0){
            			guoluMoney="<font color='red'>"+data.guoluMoney+"</font>元";
            		}else{
            			guoluMoney=data.guoluMoney+"元";
            		}
            		if(data.yuanchengMoney>0){
            			yuanchengMoney="<font color='red'>"+data.yuanchengMoney+"</font>元";
            		}else{
            			yuanchengMoney=data.yuanchengMoney+"元";
            		}
            		if(data.otherMoney>0){
            			otherMoney="<font color='red'>"+data.otherMoney+"</font>元";
            		}else{
            			otherMoney=data.otherMoney+"元";
            		}
            		
            		var addMoney="<td>-</td>";
            		if(data.status==5){
            			addMoney="<td>(过路费："+guoluMoney+"，远程费："+yuanchengMoney+"，其他费："+otherMoney+")</td>";
            		}
            		var realPay="<td>-</td>";
            		if(data.status==5){
            			realPay="<td>"+data.realPay+"元</td>";
            		}
            		
            		var tiaojiaTd="";
            		if(tiaojia){
            			tiaojiaTd="<td>"+(data.justKilometres==null?"-，":+data.justKilometres+"公里，")+(data.justMoney==null?"-":+data.justMoney+"元")+"</td>";
            		}
            		
            		//结算方式
            		var realCashTD="<td>-</td>";
            		if(data.status==5 && null!=data.preAndAfterPayType){
            			realCashTD="<td>"+(data.realPay != null ? data.realPay : 0)+"元（"+data.preAndAfterPayType+"）</td>";
            		}
            		
				    newcontent+="<tr class='grid-data tr-hui'  >"+
						"<td>"+allButton+"</td>"+
						"<td>"+status+"</td>"+
						"<td><a href='"+ctx+"/freight/orderDetails/"+data.id+"' class='btn-link'>***"+data.orderNo.substring(8,data.orderNo.length)+"</a>"+couponSpan+"</td>"+
						"<td>"+data.created+"</td>"+
						"<td>"+data.channelName+"</td>"+
						"<td>"+data.passengerName+"</td>"+
						"<td>"+data.passengerPhone+"</td>"+
						"<td>"+data.serverTime+"</td>"+
						"<td>"+data.startAddress.substring(0,15)+"...."+"</td>"+
						"<td>"+data.endAddress.substring(0,15)+"...."+"</td>"+
						realCashTD+
						"<td>"+(data.budgetPay != null ? data.budgetPay : 0)+"元</td>"+
						addMoney+
						tiaojiaTd+
						"<td>"+data.employName+"</td>"+
						"<td>"+data.employPhone+"</td>"+
						 companyNameTd+
						"<td>"+data.truckTypeName+(data.cangointotown?("--入城"):(""))+"</td>"+
						"<td>"+(data.truckTypeNumber!=null?data.truckTypeNumber:"-")+"</td>"+
						"<td>"+(data.receivedPay==true?"是 ("+data.payMount+"元)":"否")+"</td>"+
						"<td>"+(data.flitting==true?"是 ":"否")+"</td>"+
						"<td>"+(data.receipt==true?"是 ":"否")+"</td>"+
						"<td>"+(data.travelTime != null ? data.travelTime : 0)+"分钟</td>"+
						"<td>"+(data.mileage != null ? data.mileage : 0)+"公里</td>"+
						"<td>"+(data.waitTime != null ? data.waitTime : 0)+"分钟</td>"+
						"<td>"+(data.waitCost != null ? data.waitCost : 0)+"元</td>"+
						"<td>"+(memotr==null||memotr =="null" ? "" : memotr)+"</td>"+
						"<td>"+data.cancelCause+"</td>"+
						"<td>"+allButton+"</td>"+
					"</tr>";
        		});
        	}
        	else{
              	 $("#NoData").text("当前页面暂无记录 ");
              	}
        	
        	if(!isappend){
        		$("#order_tbody .grid-data").remove();
        	}
        	$("#order_tbody").append(newcontent);
        	$("#order_tbody .grid-data").each(function(index,element){
        		$(element).fadeIn(200+(index*35));
        	});
        	if(!hasShowPages){
        		if(!isappend){
            		currentTotalElements=result.content.length;
            		pageLoading=true;
            	}else{
            		if(currentTotalElements<totalElements){
            			currentTotalElements+=result.content.length;
            			pageLoading=true;
            		}else{
            			pageLoading=false;
            		}
            	}
        	}
        	if(hasShowPages){
    			firstLoadPages=true;
        		$(".pageshow li a").html("共"+totalElements+" 条数据");
        		$(".pagedata").paging(totalElements, {
        			format: '[< ncnnn >]',
        			perpage: pagingLimit,
        			page:(offset/limit)+1,
        			onSelect: function (page) {
        				limit=pagingLimit;
        				offset=(page-1)*limit;
        				if(!firstLoadPages){
        					initdata(false);
        				}
        				firstLoadPages=false;
        		    	return false;
        			},
        			onFormat: function (type) {
        				switch (type) {
        				case 'block': // n and c
        					if (!this.active)
        						return '';
        					else if (this.value != this.page)
        						return '<li><a href="#">' + this.value + '</a></li>';
        					return '<li class="active"><a href="#">' + this.value + '</a></li>';
        				case 'next': // >
        					return '<li><a href="#">&rsaquo;</a><li>';
        				case 'prev': // <
        						return '<li><a href="#">&lsaquo;</a><li>';
        				case 'first': // [
        						return '<li><a href="#">&laquo;</a><li>';
        				case 'last': // ]
        						return '<li><a href="#">&raquo;</a></li>';
        				}
        			}
        		});
        	}else{
        		//滚动达到pagingLimit条开始显示分页
//        		if(currentTotalElements==pagingLimit){
            		pageLoading=false;
            		hasShowPages=true;
            		$(".pageshow").show();
            		$(".pagedata").show();
            		$(".pageshow li a").html("共"+totalElements+" 条数据");
            		$(".pagedata").paging(totalElements, {
            			format: '[< ncnnn >]',
            			perpage: pagingLimit,
            			onSelect: function (page) {
            				limit=pagingLimit;
            				offset=(page-1)*limit;
            				if(!firstLoadPages){
            					initdata(false);
            				}
            				firstLoadPages=false;
            		    	return false;
            			},
            			onFormat: function (type) {
            				switch (type) {
            				case 'block': // n and c
            					if (!this.active)
            						return '';
            					else if (this.value != this.page)
            						return '<li><a href="#">' + this.value + '</a></li>';
            					return '<li class="active"><a href="#">' + this.value + '</a></li>';
            				case 'next': // >
            					return '<li><a href="#">&rsaquo;</a><li>';
            				case 'prev': // <
            						return '<li><a href="#">&lsaquo;</a><li>';
            				case 'first': // [
            						return '<li><a href="#">&laquo;</a><li>';
            				case 'last': // ]
            						return '<li><a href="#">&raquo;</a></li>';
            				}
            			}
            		});
//            	}
        	}
        }
	});
}
function showClientMaker(lng,lat){
	var point=new BMap.Point(lng,lat);
	map = new BMap.Map("allmap");  
	map.centerAndZoom(point, 14);
	map.enableScrollWheelZoom();
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);
	
	map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_RIGHT, mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));
    
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮
    
    var ctrl = new BMapLib.TrafficControl({
       showPanel: false //是否显示路况提示面板
    });
    map.addControl(ctrl);
    ctrl.setAnchor(BMAP_ANCHOR_TOP_LEFT);
}
function getDrivers(lng,lat){
	var distance=$("#distance").val();
	var orderId=$("#paidanOrderId").val();
	$.get(ctx+'/driver/freightListDrivers',{'lng':lng,'lat':lat,'distance':distance,'orderId':orderId},function(data){
		if(data && data.length>0){
			$("#paidanDrivers").html('');
			$(data).each(function(i,driver){
				var detailStatus='';
				if(!driver.workCar){
					detailStatus='kongxian';
				}else{
					detailStatus='workcar';
				}
				var htm='<div id="driver_marker_'+driver.id+'" class="sj-mark driver_marker_class" style="position:absolute;z-index:9;">'+
							'<div class="sj-mark-ma sjcolor-'+detailStatus+'"><span>'+driver.realname+'</span></div>'+
							'<div class="sj-mark-rk rkcolor-'+detailStatus+'"></div>'+
					    '</div>';
				if(driver.workCar){
					htm='<div id="driver_marker_'+driver.id+'" class="driver_workcar_marker_class" data-z-index="9998" style="position:absolute;z-index:9998;width:110px;">'+
				        	'<div class="em-'+detailStatus+'-l"></div>'+
				    		'<div class="em-'+detailStatus+'-con">'+driver.realname+'</div>'+
				            '<div class="em-'+detailStatus+'-r"></div>'+
				        '</div>';
				}
			    var driverpoint = new BMap.Point(driver.longitude,driver.latitude);
				var drivermarker = new BMapLib.RichMarker(htm, driverpoint, {"anchor": new BMap.Size(-62, -40), "enableDragging": true});
				drivermarker.driverid=driver.id;
				drivermarker.driverstatus=driver.status;
				map.addOverlay(drivermarker);
				$("#paidanDrivers").append("<div class='modal-sj-bd' style='display:none;'><button type='button' class='f_paigeita' data-id='"+driver.id+"'>派给</button><span>"+driver.realname+"</span><span>"+driver.phone+"</span><span style='font-size:12px;'>"+driver.distanceStr+"</span></div>");
			});
			$(".f_paigeita").each(function(index,element){
        		$(element).parent().fadeIn((index+1)*300);
        	});
		}else{
			$("#paidanDrivers").html(distance+"公里范围内暂无推荐服务人员，您可以扩大范围看看。");
		}
	});
}
function showLoading(){
	if($('#loadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$("#order_tbody").append(backlayer);
		$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
}
function hideLoading(){
	if($('#loadblacklayer').length>0){
		$('#loadblacklayer').remove();
	}
}
Date.prototype.Format = function(fmt) 
{ 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  for(var k in o) 
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  return fmt; 
}
